import 'dart:convert';
import 'dart:io';
import 'dart:math';

// import 'package:device_info/device_info.dart';
import 'package:crypto/crypto.dart';
import 'package:device_info/device_info.dart';

// import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';

// import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/utils/utils_other.dart';
import 'package:flutter_syt/widgets/common_button.dart';

// import 'package:fluwx/fluwx.dart';
import 'package:in_app_review/in_app_review.dart';

// import 'package:flutter_share/flutter_share.dart';
// import 'package:launch_review/launch_review.dart';
import 'package:flutter_syt/datas/station_item.dart';
import 'package:flutter_syt/datas/user_info.dart';
import 'package:flutter_syt/domain/message/message_sub_list.dart';
import 'package:flutter_syt/domain/mine/signin_page.dart';
import 'package:flutter_syt/domain/test/nucleic_acid_report.dart';
import 'package:flutter_syt/domain/test/submission_file_upload.dart';
import 'package:flutter_syt/domain/waystation/map_helper.dart';
import 'package:flutter_syt/domain/widgets/common_dialog.dart';
import 'package:flutter_syt/domain/widgets/custom_dialog.dart';
import 'package:flutter_syt/global_easy_loading.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';
import 'package:flutter_syt/widgets/web_html.dart';
import 'package:flutter_syt/widgets/web_video_page.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

// import 'package:fluwx/fluwx.dart' as Fluwx;
class _DebugEntity {
  late String label;
  late GestureTapCallback? onTap;

  _DebugEntity();

  factory _DebugEntity.create(String label, GestureTapCallback? onTap) {
    return _DebugEntity()
      ..label = label
      ..onTap = onTap;
  }
}

class TestPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  void _getPlatform() async {
    try {
      if (Platform.isAndroid) {
        var deviceData = appContext.andriodInfo;
        EasyLoading.showToast('平台名称为 ${deviceData.brand}');
      }
    } catch (e) {}
  }

  String buildUrl() {
    return '''
<!DOCTYPE html>
<!-- 测试拍照和选择图片 -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Flutter InAppWebView</title>
    <link rel="stylesheet" href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <link rel="shortcut icon" href="favicon.ico">
</head>
<body class="text-center" style="background-color:#cccccc">
    <div>
        普通输入没有capture字段: <input type="file" name="uploadfile">&nbsp;&nbsp;
    </div>

    <div>
        属性中带有capture:<input type="file" accept="image/*" capture>
    </div>

    <div>
        属性中带有capture="user":<input accept="image/*" capture="user" id="imgFile" name="imgFile"  type="file">&nbsp;&nbsp;
    </div>

    <script src="js/main.js"></script>
</body>
</html>

''';
  }

// appContext.storage.getString("registrationID")
  @override
  Widget build(BuildContext context) {
    // EasyLoading.dismiss();
    List<_DebugEntity> _list = [


      _DebugEntity.create("下载文件到文件", () async {
        UtilsOther.downloadPdfToAppFiles(
            'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
            'dummy.pdf');
        // Fluwx fluwx = Fluwx();
        // fluwx.registerApi(
        //     appId: "wx2846539763f489ad",
        //     universalLink: "https://your.univerallink.com/link/");
        //
        // fluwx.open(
        //     target: MiniProgram(
        //         username: 'gh_9e6316035626',
        //         miniProgramType: WXMiniProgramType.release));
        // launchUrlString('weixin://dl/business/?appid=wxf0f8b911ac324457',
        //     mode: LaunchMode.externalApplication);

        // weixin://dl/business/?appid=$appId
        // customShowError('csdfc');
        // RouteManager.push(context, e.path ?? '');
        // RouteManager.push(
        //   context,
        //   RoutMapping.epidemicHome(),
        // );
        // LaunchReview.launch(iOSAppId: '1601140897', writeReview: false);

        // LaunchReview.launch(androidAppId: "com.iyaffle.rangoli",
        // iOSAppId: "1601140897");
        // itms-apps://itunes.apple.com/app/id
        // const url =
        //     'https://itunes.apple.com/us/app/your-app-name/id1601140897';
        // const url =
        // 'itms-apps://itunes.apple.com/us/app/your-app-name/id1601140897';
        // if (await canLaunc(url)) {?ls=1&mt=8
        // await launchUrlString(url);
        // } else {
        // throw 'Could not launch $url';
        // }
        // RouteManager.push(
        //     context, 'yyy://page/epidemic_health_list_page?type=0');
        // "yyy://page/service_socket?$paramStr"
        // game_live_list
        // RouteManager.push(
        //     context,
        //     RoutMapping.paymentDesk(jsonEncode({
        //       "order_id": "23042022312264414cbac5be0364",
        //       "total_fee": "0.01",
        //       "body": " x",
        //       "pay_mode": "1,2,3,4,5"
        //     })));
        // flu
        // fluwx.
        // await registerWxApi(
        //     appId: "wx098f1de5776fbc74",
        //     universalLink: "https://app.api.2021chengdu.com/app/");
        // payWithWeChat(
        //     appId: 'wx098f1de5776fbc74',
        //     partnerId: '1440729102',
        //     prepayId: 'wx2009582970660205f591f3cc5d0b210000',
        //     packageValue:
        //         "{\"package\":\"Sign=WXPay\",\"appid\":\"wx098f1de5776fbc74\",\"sign\":\"2EMc+OQgJ8NSAjJhaPiBcl5SigxAHmWbrI8xQrvBQpiiA2Ht3xDVJQt2teaxMRqmXzWLxW9bM9m8w9z17FZz+MstESivMBs15TgRO8ArMBxweR9fl74zd7SE5X8Ee13kihYzi602C6H9THwYmBhHZfgfB8idVEhUK/viAGd52Uaoc/RuEXMAdRjiU27HKi3j0hWkAvb2fTf6CAr5SwTW8wd/zql0sgfILjXrAL/k4JZlY4qWDAq15q/HTJmnMTwoyhyO2wtCaMAXMgqBy9iV8B9SKe1dJJjuZyFVbBUR636uYLDlbrU/+nSHXtw1AB8Et9RCJJ5mKbHTqatNMloDOg==\",\"partnerid\":\"1440729102\",\"prepayid\":\"wx2009582970660205f591f3cc5d0b210000\",\"noncestr\":\"2a4451f0dbd54489b0eabf74e2c778e5\",\"timestamp\":\"1681955909\"}",
        //     nonceStr: '2a4451f0dbd54489b0eabf74e2c778e5',
        //     timeStamp: 1681955909,
        //     sign:
        //         '2EMc+OQgJ8NSAjJhaPiBcl5SigxAHmWbrI8xQrvBQpiiA2Ht3xDVJQt2teaxMRqmXzWLxW9bM9m8w9z17FZz+MstESivMBs15TgRO8ArMBxweR9fl74zd7SE5X8Ee13kihYzi602C6H9THwYmBhHZfgfB8idVEhUKviAGd52UaocRuEXMAdRjiU27HKi3j0hWkAvb2fTf6CAr5SwTW8wdzql0sgfILjXrALk4JZlY4qWDAq15qHTJmnMTwoyhyO2wtCaMAXMgqBy9iV8B9SKe1dJJjuZyFVbBUR636uYLDlbrU+nSHXtw1AB8Et9RCJJ5mKbHTqatNMloDOg==');

        // {"code":200,"message":"OK","data":{"order_no":"23042009581764409c397cabb779","total_fee":1,"redirect_url":"https://dev.mall.zhuoxinyoupin.com/mall/orderDetail?group_id=0&orderId=1060&store_id=27&lang=zh","pay_mode":"2","pay_data":{"access_type":"5","card_kind":"","mer_id":"440204161496","wx_data_package":"{\"package\":\"Sign=WXPay\",\"appid\":\"wx098f1de5776fbc74\",\"sign\":\"2EMc+OQgJ8NSAjJhaPiBcl5SigxAHmWbrI8xQrvBQpiiA2Ht3xDVJQt2teaxMRqmXzWLxW9bM9m8w9z17FZz+MstESivMBs15TgRO8ArMBxweR9fl74zd7SE5X8Ee13kihYzi602C6H9THwYmBhHZfgfB8idVEhUK/viAGd52Uaoc/RuEXMAdRjiU27HKi3j0hWkAvb2fTf6CAr5SwTW8wd/zql0sgfILjXrAL/k4JZlY4qWDAq15q/HTJmnMTwoyhyO2wtCaMAXMgqBy9iV8B9SKe1dJJjuZyFVbBUR636uYLDlbrU/+nSHXtw1AB8Et9RCJJ5mKbHTqatNMloDOg==\",\"partnerid\":\"1440729102\",\"prepayid\":\"wx2009582970660205f591f3cc5d0b210000\",\"noncestr\":\"2a4451f0dbd54489b0eabf74e2c778e5\",\"timestamp\":\"1681955909\"}","return_msg":"success","attch":"","pay_time":"20230420","total_amt":"1","pay_mode":"9","out_trade_no":"23042009581764409c397cabb779","prepayId":"wx2009582970660205f591f3cc5d0b210000","msg_id":"050200023110818095829170270","return_code":"0","order_id":"440204161496000582304200001055"}}}
        // Fluwx.payWithWeChat(appId: appId, partnerId: partnerId, prepayId: prepayId, packageValue: packageValue, nonceStr: nonceStr, timeStamp: timeStamp, sign: sign)
      }),
      _DebugEntity.create(
          "直播列表", () => RouteManager.push(context, RoutMapping.gameLiveList())),
      _DebugEntity.create("视频列表",
          () => RouteManager.push(context, RoutMapping.gameVideoList())),
      _DebugEntity.create("推送测试", () async {
        // PermissionHelper.checkLocationPermission(context);
        // checkLocationPermission
        // Intl.systemLocale
        // showCommonDialog(
        //     context,
        //     DialogEntity(S().permission_tips, Text(S().pay_tips),
        //         () => Navigator.of(context).pop(), () {
        //       Navigator.push(context,
        //           MaterialPageRoute(builder: (context) => WebHtmlPage('')));
        //     }, cancelText: S.of(context).cancel, okText: S.of(context).sure));
        // DLog(Intl.systemLocale);
      }),
      // EncryptUtils

      _DebugEntity.create('打开appstore', () {
        InAppReview.instance.openStoreListing(
            appStoreId: '1601140897',
            microsoftStoreId: 'com.cdinternationalcompany.syhapp');

        // LaunchReview.launch(
        //     androidAppId: 'com.zxljcompany.huixq',
        //     iOSAppId: '1601140897',
        //     writeReview: false);

        // utf8.encode('cadscvasd');
        // sha256.convert(utf8.encode('221.237.107.207'));
        // DLog(EncryptUtils.decryptNewAES(
        //     't8ix9W1upjvFcv62wfra/jk333VEz5TfyueLdHNA9jSQ9ZHHt8uk3TiuIH30EcbDiWJ7fPXdT3AprTpqnOPELpcu3/h1vMUmj8QzMll1skkLFTJWmEQnq3XZkvjCHWiU'));
        // DLog(sha256.convert(utf8.encode('221.237.107.207')));
        // AndroidDeviceInfo androidDeviceInfo = appContext.andriodInfo;
        // DLog(appContext.andriodInfo);
        // DLog(
        //     'rZH/JYMWl9Q2RU3tHQYi66YdQc+aI/O6DtrIGgEo2pv2rCTeLE0xSum8SQds+aYQtu0pTkYZiBLukZKoPy8a62MWIXnXtzar0ju3s/3chOVULHXvC7CypmftHj1YDO8zL3CF5No3gubkGMSYyo5xS/x9nyluswytoDMJtwFEqxM='
        //         .rsa);
        // var publicKeyStr = await rootBundle.loadString('assets/data/rsa_private_key.pem');
        // var publicKey =  RSAKeyParser().parse('rZH/JYMWl9Q2RU3tHQYi66YdQc+aI/O6DtrIGgEo2pv2rCTeLE0xSum8SQds+aYQtu0pTkYZiBLukZKoPy8a62MWIXnXtzar0ju3s/3chOVULHXvC7CypmftHj1YDO8zL3CF5No3gubkGMSYyo5xS/x9nyluswytoDMJtwFEqxM=');
        // final encrypter = Encrypter(RSA(publicKey: publicKey));
        //   encrypter.decrypt(Encrypted.fromBase64(content));
        // Navigator.push(context,
        //     MaterialPageRoute(builder: (context) => WebSocketTestPage()));
      }),
      _DebugEntity.create('客服', () {
        // utf8.encode('cadscvasd');
        // sha256.convert(utf8.encode('221.237.107.207'));
        DLog(sha256.convert(utf8.encode('221.237.107.207')));
        // AndroidDeviceInfo androidDeviceInfo = appContext.andriodInfo;
        // DLog(appContext.andriodInfo);
        // DLog(
        //     'rZH/JYMWl9Q2RU3tHQYi66YdQc+aI/O6DtrIGgEo2pv2rCTeLE0xSum8SQds+aYQtu0pTkYZiBLukZKoPy8a62MWIXnXtzar0ju3s/3chOVULHXvC7CypmftHj1YDO8zL3CF5No3gubkGMSYyo5xS/x9nyluswytoDMJtwFEqxM='
        //         .rsa);
        // var publicKeyStr = await rootBundle.loadString('assets/data/rsa_private_key.pem');
        // var publicKey =  RSAKeyParser().parse('rZH/JYMWl9Q2RU3tHQYi66YdQc+aI/O6DtrIGgEo2pv2rCTeLE0xSum8SQds+aYQtu0pTkYZiBLukZKoPy8a62MWIXnXtzar0ju3s/3chOVULHXvC7CypmftHj1YDO8zL3CF5No3gubkGMSYyo5xS/x9nyluswytoDMJtwFEqxM=');
        // final encrypter = Encrypter(RSA(publicKey: publicKey));
        //   encrypter.decrypt(Encrypted.fromBase64(content));
        // Navigator.push(context,
        //     MaterialPageRoute(builder: (context) => WebSocketTestPage()));
      }),
      _DebugEntity.create('签到页', () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (bld) => SignInPage()));
      }),
      _DebugEntity.create('世运之眼', () async {
        EasyLoading.instance.flash(() async {
          await Future.delayed(Duration(
            seconds: 1,
          ));
        });
      }),
      _DebugEntity.create('设备信息', () async {
        // AndroidDeviceInfo androidDeviceInfo = appContext.andriodInfo;
        // DLog(androidDeviceInfo.toString());
        // // if (Platform.isIOS) {
        // appContext.deviceBrand = androidDeviceInfo.brand;
        // appContext.deviceVersion = androidDeviceInfo.display;
        // }
      }),
      _DebugEntity.create('健康防疫', () async {
        // LocationHelper.instance.result((data) {
        //   DLog(data.location?.latitude);
        // });
        WebHtmlPage webHtmlPage = WebHtmlPage('''<!DOCTYPE html>
<!-- 测试拍照和选择图片 -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Flutter InAppWebView</title>
    <link rel="stylesheet" href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <link rel="shortcut icon" href="favicon.ico">
</head>
<body class="text-center" style="background-color:#cccccc">
    <div>
        普通输入没有capture字段: <input type="file" name="uploadfile">&nbsp;&nbsp;
    </div>

    <div>
        属性中带有capture:<input type="file" accept="image/*" capture>
    </div>

    <div>
        属性中带有capture="user":<input accept="image/*" capture="user" id="imgFile" name="imgFile"  type="file">&nbsp;&nbsp;
    </div>

    <script src="js/main.js"></script>
</body>
</html>''');

        // LocationHelper.startLocation();
        // DLog(UserInfo.me.id);
        // RouteManager.push(context, 'yyy://toast?message=开发中，敬请期待');
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (bld) => webHtmlPage));
      }),
      _DebugEntity.create('获取token', () async {
        DLog('UserInfo.me.token ${UserInfo.me.token}');
        // showCommonDialog(
        //     context,
        //     DialogEntity(S().permission_tips, Text(S().pay_tips),
        //         () => Navigator.of(context).pop(), () async {
        //       Navigator.of(context).pop();
        //       await Future.delayed(Duration.zero);
        //       Navigator.push(
        //           context,
        //           MaterialPageRoute(
        //               builder: (context) => WebHtmlPage('payData')));
        //     }, cancelText: S.of(context).cancel, okText: S.of(context).sure));
        // LocationHelper.instance.result((data) {
        //   print(data.location?.latitude);
        // });
        // LocationHelper.instance.startLocation();
        // BMFCoordinate coo0 = BMFCoordinate(39.965, 116.304);
        // BMFCoordinate coo1 = BMFCoordinate(39.865, 116.304);
        // DLog(_getDistance(coo0, coo1));
        // double? arfuture =
        //     await BMFCalculateUtils.getLocationDistance(coo0, coo1);
        // // arfuture.then((onValue) {
        // BMFLog.d('distance:' + arfuture.toString());
        // LocationHelper.startLocation();
        // RouteManager.push(context, 'yyy://toast?message=开发中，敬请期待');
        // Navigator.of(context)
        //     .push(MaterialPageRoute(builder: (bld) => SignInPage()));
      }),
      _DebugEntity.create('餐饮', () async {
        var web = WebVideoPage('http://221.237.109.31:8052/DYHH5-TEST');
        Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => web,
            settings: RouteSettings(name: "web_in_view", arguments: "")));
      }),
      _DebugEntity.create('测试链接跳转', () async {
        // try {
        //   LocationHelper.instance.result((LocationData event) async {
        //     DLog(event.toString());
        //     if (event.location?.latitude != null) {
        //       // _locationData = event;
        //     }
        //     // calculationDistance();
        //   });
        //   await LocationHelper.instance.startLocation();
        // } catch (e) {}
        // RouteManager.push(context, RoutMapping.webDetail('https://maasuat2.paircity.com:5443/maas/dashboard/h5/maas_h5_index.html?lang=zh'));
        // RouteManager.push(
        //     context,
        //     RoutMapping.webDetail(
        //         'http://chengdu2021.cdmaas.cn:20080/h5/index.html?lang=zh'));
      }),
      _DebugEntity.create('支付网页html测试', () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (bld) => WebHtmlPage(buildUrl())));
      }),
      _DebugEntity.create('核酸检测报告页', () {
        Navigator.of(context).push(
            MaterialPageRoute(builder: (bld) => NucleicAcidReportPage(true)));
      }),
      _DebugEntity.create('安卓平台名称获取', () {
        _getPlatform();
      }),
      _DebugEntity.create('AR', () {
        Share.shareUri(
          Uri.parse('https://www.baidu.com'),
        );
        //   FlutterShare.share(
        //       title: '这是标题',
        //       text: '这是内容',
        //       linkUrl: 'https://www.baidu.com',
        //       chooserTitle: '这是AA');
      }),
      _DebugEntity.create('文件上传页', () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (builder) => SubmissionFileUploadPage()));
      }),
      _DebugEntity.create("跳消息详情页", () {
        final entity = StationItem({});
        entity.pushlish_user_id = '17';
        entity.account_name = '';
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (ctx) => MessageSubList(entity)));
      }),
      _DebugEntity.create(
          '支付页',
          () => RouteManager.push(
              context,
              RoutMapping.paymentDesk(
                  '{"oder_id":"123","total_fee":"333","body":"烧烤鸡翅膀"}'))),
      _DebugEntity.create(
          "注册", () => RouteManager.push(context, RoutMapping.register())),
      _DebugEntity.create(
          "验证码登录", () => RouteManager.push(context, RoutMapping.loginByCode())),
      _DebugEntity.create(
          "密码登录", () => RouteManager.push(context, RoutMapping.loginByPwd())),
      _DebugEntity.create(
          "列表Item", () => RouteManager.push(context, RoutMapping.testList())),
      _DebugEntity.create(
        "弹窗",
        () => {
          showCommonDialog(
            context,
            DialogEntity(
                '个人信息保护指引',
                Text(
                    '感谢您使用世运通APP，我们非常重视个人隐私及个人信息保护，在您使用该APP的过程中，我们可能会对您的部分个人信息进行收集、使用和共享，请您认真阅读《隐私协议》的全部条款，并确认我们对您信息处理的规则和方式，在您接受并点击“同意”后，再开始使用我们为您提供的服务，我们会尽全力保护您的个人信息安全。'),
                () {
              Navigator.of(context).pop();
            }, () {
              Navigator.of(context).pop();
            }, cancelText: '555'),
          )
        },
      ),
      _DebugEntity.create("普通用户小站",
          () => RouteManager.push(context, RoutMapping.normalUserWayStation())),
      _DebugEntity.create("志愿者小站",
          () => RouteManager.push(context, RoutMapping.volunteerWayStation())),
      _DebugEntity.create("普通用户小站",
          () => RouteManager.push(context, RoutMapping.normalUserWayStation())),
      _DebugEntity.create("志愿者小站",
          () => RouteManager.push(context, RoutMapping.volunteerWayStation())),
      _DebugEntity.create("视频播放页面", () {
        RouteManager.push(context, RoutMapping.videoDetail("11140"));
      }),
      _DebugEntity.create(
          "设置页", () => RouteManager.push(context, RoutMapping.settingPage())),
      _DebugEntity.create(
          "本地列表", () => RouteManager.push(context, RoutMapping.testCardPage())),
      _DebugEntity.create(
          "运动列表", () => RouteManager.push(context, RoutMapping.sportsList())),
      _DebugEntity.create("打开ar页面", () {
        // appContext.channelApi.openAR();
      }),
      _DebugEntity.create("显示loading", () {}),
    ];
    return Scaffold(
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(6),
          children: [
            CommonButton.expend(
              title: 'title',
              onAsyncClick: () async {
                await Future.delayed(Duration(seconds: 3));
              },
            ),
            ..._list
                .map((e) => GestureDetector(
                      onTap: e.onTap,
                      child: Container(
                        margin: EdgeInsets.symmetric(vertical: 5),
                        padding: EdgeInsets.all(10),
                        width: double.infinity,
                        color: Colors.blueGrey,
                        alignment: Alignment.center,
                        child: Text(e.label, style: TextStyle(fontSize: 16)),
                      ),
                    ))
                .toList()
          ],
        ),
      ),
    );
  }

// _getDistance(BMFCoordinate startCoord, BMFCoordinate endCoord) {
//   /// 单位：米
//   double def = 6378137.0;
//   double radLat1 = _rad(startCoord.latitude);
//   double radLat2 = _rad(endCoord.latitude);
//   double a = radLat1 - radLat2;
//   double b = _rad(startCoord.longitude) - _rad(startCoord.longitude);
//   double s = 2 *
//       asin(sqrt(pow(sin(a / 2), 2) +
//           cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2)));
//   return (s * def).roundToDouble();
// }
//
// double _rad(double d) {
//   return d * pi / 180.0;
// }
}
